<template>
  <!-- <div :class="className" :style="{height:height,width:width}" /> -->
  <div class="com_container">
    <el-card class="box-card">
     
      <div slot="header" class="clearfix">
        <el-row type="flex" justify="center">
          <span>{{ title }}</span>
        </el-row>
        <el-button
          style="float: right; padding: 3px 0"
          type="text"
          v-if="cardLeft"
          >操作按钮</el-button
        >
      </div>
      <div style="text-align: center; margin-bottom: 20px;">
        <el-select
						v-model="StatisticalIndicator"
						collapse-tags
						filterable
            clearable
						placeholder="排序方式"
						style="width: 120px; margin: 0 10px 0 0px"
            @change="getDataFn()"
					>
						<el-option :label="'星币'" :value="0" />
						<el-option :label="'扫码次数'" :value="1" />
				</el-select>
        <el-select
						v-model="RankedEntity"
						collapse-tags
						filterable
						placeholder="选择类型"
						style="width: 150px; margin: 0 10px 0 0px"
            @change="getDataFn()"
					>
						<el-option v-for="item in RankedEntityList" :key="item.id" :label="item.name" :value="item.value" />
					</el-select>
         <el-date-picker v-model="BeginTime" @change="getDataFn()" type="datetime" style="margin-right: 10px; width: 150px;" placeholder="开始时间"></el-date-picker>
					<el-date-picker v-model="EndTime" @change="getDataFn()" type="datetime" placeholder="结束时间" style="width: 150px;"></el-date-picker>
      </div>
      <el-table
        :data="list"
      >
      <el-table-column
					align="center"
					type="index"
					:index="indexMethod"
					label="排行"
					width="80"></el-table-column>
        <el-table-column :label="RankedEntityList[RankedEntity].name" align="center">
          <template slot-scope="{ row }">
            {{ row.name }}
          </template>
        </el-table-column>
        <el-table-column label="星币" align="center">
          <template slot-scope="scope">
            {{ scope.row.points}}
          </template>
        </el-table-column>
        <el-table-column label="扫码次数" align="center">
          <template slot-scope="scope">
            {{ scope.row.scanCount }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
import {GetRankingList} from '@/api/goodList';
import {guid} from '@/utils/index'
export default {
  data() {
    return {
      list: [ ],
      BeginTime:'',
      EndTime:'',
      fillterRole:'',
      RoleList:[],
      RankedEntity:0,
      RankedEntityList:[
        {value:0,name:'业务员',id:guid()},
        {value:1,name:'销售区域',id:guid()},
        {value:2,name:'省',id:guid()},
        {value:3,name:'市',id:guid()},
        {value:4,name:'商品',id:guid()},
      ],
      countUnit:"",
      pointUnit:"",
      StatisticalIndicator:''
    }
  },
  props: {
    cardLeft: {
      type: Boolean,
      default: false,
    },
    height: {
      type: String,
      default: "600px",
    },
    title: {
      type: String,
      default: "卡片名称",
    },
  },
  created(){
    this.getDataFn();
  },
  methods: {
     //表格编号设置
		 indexMethod(index){
				return index+1;
		},
    async getDataFn(){
      let params = {
        RankedEntity:this.RankedEntity,
      };
      if(this.StatisticalIndicator !==''){
        params.StatisticalIndicator = this.StatisticalIndicator;
      }
      if(this.BeginTime !==''){
        params.BeginTime = this.BeginTime;
      }
      if(this.EndTime !==''){
        params.EndTime = this.EndTime;
      }
      const res = await GetRankingList(params)
      console.log(res);
      if(res.code === 200){
        this.countUnit = res.data.countUnit;
        this.pointUnit = res.data.pointUnit;
        this.list = res.data.rankingList;
      }else{
        this.$message.error('获取拓展数据失败')
      }
    },
    getLocalTime: function (nS) {
      return new Date(parseInt(nS) * 1000)
        .toLocaleString()
        .replace(/:\d{1,2}$/, " ");
    },
    statusType: function (status) {
      const statusTex = {
        1: "草稿",
        2: "等待审批",
        3: "开始审批",
        4: "已拒绝",
        5: "已同意",
        6: "已完成",
      };
      return statusTex[status] || "无";
    },
    columnColor: function (row) {
      const statusTex = {
        1: "",
        2: "wait-row",
        3: "start-row",
        4: "failed-row",
        5: "ageen-row",
        6: "success-row",
      };
      if(row.rowIndex === this.list.length-1){
        return 'success-row'
      }else{
        return statusTex[row.row.status] || "";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.com_container {
  width: 100%;
  height: 100%;
  padding: 0px;
}
.box-card {
  margin-bottom: 20px;
}
.box-card::v-deep .el-card__header{
  background: #ffdab9;
} 
.table-header-bg {
  background: #ff8247;
}
.el-table .wait-row {
  background: #ffffe0;
}
.el-table .start-row {
  background: #bfefff;
}
.el-table .failed-row {
  background: #ffaeb9;
}
.el-table .ageen-row {
  background: #b4eeb4;
}

</style>
<style >
.success-row {
  background-color: #ffdab9 !important;
}
</style>